
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>BeanFactory和ApplicationContext的区别? - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>BeanFactory和ApplicationContext的区别? - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">从功能和接口关系上看，Spring中的`ApplicationContext`和`BeanFactory`有何本质区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`BeanFactory`是Spring最基本的Bean容器接口，提供Bean的实例化、依赖注入和生命周期管理等核心功能。而`ApplicationContext`是`BeanFactory`的子接口，它不仅继承了`BeanFactory`的所有功能，还扩展了更多企业级特性，如国际化支持、事件传播和AOP等。</div>
          </div>
          <div class="card-source">来源: 功能不同</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`BeanFactory`和`ApplicationContext`在Bean的实例化时机上（加载策略）有何不同？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`BeanFactory`采用延迟加载（lazy-loading）策略，只有在客户端首次请求获取某个Bean时，容器才会对其进行实例化和初始化。相反，`ApplicationContext`采用预实例化（eager-loading）策略，在容器启动时就会自动实例化并初始化所有配置的单例（singleton）Bean。</div>
          </div>
          <div class="card-source">来源: 预实例化不同</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`ApplicationContext`提供了哪些`BeanFactory`所不具备的扩展企业级功能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`ApplicationContext`提供了多种`BeanFactory`没有的扩展接口，例如用于国际化处理的`MessageSource`接口和用于应用内事件传播的`ApplicationEventPublisher`接口等。</div>
          </div>
          <div class="card-source">来源: 扩展接口不同</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Bean的销毁和资源回收方面，`BeanFactory`和`ApplicationContext`的管理方式有何差异？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`BeanFactory`管理的Bean对象由JVM的垃圾回收器负责回收，当Bean不再被引用时由JVM自动处理。而`ApplicationContext`在容器关闭时，会主动调用销毁方法，自动销毁其管理的所有单例Bean，从而释放占用的资源。</div>
          </div>
          <div class="card-source">来源: 垃圾回收不同</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">尽管`ApplicationContext`功能更强大，但在什么特定场景下我们可能会选择使用`BeanFactory`？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在对资源要求比较低，或者需要对BeanFactory的实现进行高度自定义的场景下，可以选择使用`BeanFactory`来管理Bean。在大多数企业级应用中，`ApplicationContext`因其丰富的功能而更为常用。</div>
          </div>
          <div class="card-source">来源: 文档结尾总结部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">为什么说`ApplicationContext`是`BeanFactory`的超集？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为`ApplicationContext`是`BeanFactory`的子接口，它完全继承了`BeanFactory`作为Bean容器的基本功能，并且在此基础上增加了大量企业级应用所需的额外功能和特性，因此在功能范围上是`BeanFactory`的超集。</div>
          </div>
          <div class="card-source">来源: 文档结尾总结部分</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
